package week1;

public class Ex10 {
    public static void main(String[] args) {
        int n = 2000000;
        long sum = 0;
        int[] prime = new int[n];
        int c = 0;
        boolean[] isVisit = new boolean[n+1];
        for (int i = 2; i <= n; i++) {
            if (!isVisit[i]){
                prime[++c] = i;
                sum += i;
            }
            for (int j = 1; j <= c && i * prime[j] <= n; ++j){
                isVisit[i * prime[j]] = true;
                if (i % prime[j] == 0)
                    break;
            }
        }
        System.out.println(sum);
    }
}
